<template>
  <div class="ContentWrap">
    <div class="header">
      <van-sticky>
        <van-nav-bar title="在线问诊" />
      </van-sticky>
    </div>
    <div class="main">
      <van-search
        v-model="value"
        shape="round"
        @click="jumpSearchpages"
        placeholder="搜医院、医生、科室、疾病"
      />
      <div style="position: relative">
        <h2
          style="
            display: inline-block;
            height: 0.5rem;
            line-height: 0.6rem;
            margin-left: 0.1rem;
          "
        >
          看专家
        </h2>
        <span style="color: #ccc">&emsp;指定医生 获取专业意见</span>
        <span
          style="position: absolute; right: 0.1rem; top: 0.22rem"
          @click="ContentList"
          >全部医生></span
        >
      </div>
      <div class="box">
        <div>
          <van-tabs
            v-model:active="active"
            @click-tab="onChange(title, active)"
          >
            <van-tab v-for="item in ContentTitle" :key="item.id" :title="item">
              <div
                class="box1"
                v-for="(item, index) in ContentData"
                :key="index"
                @click="btnvanListDiv(item)"
              >
                <dl>
                  <dt>
                    <img v-lazy="item.img" alt="" />
                  </dt>
                  <dd>
                    <p>
                      {{ item.name }} <span>{{ item.state }}</span>
                    </p>
                    <p>{{ item.nosocomium }}</p>
                    <p>擅长:{{ item.department }}</p>
                  </dd>
                </dl>
              </div>
            </van-tab>
          </van-tabs>
        </div>
        <van-button
          style="position: absolute; bottom: 0.05rem; left: 1.5rem"
          plain
          round
          type="primary"
          size="small"
          @click="ContentList"
          ><b>更多专家</b></van-button
        >
      </div>
      <div>
        <h2
          style="
            display: inline-block;
            height: 0.5rem;
            line-height: 0.5rem;
            margin-left: 0.1rem;
            margin-top: 0.1rem;
          "
        >
          快速问诊
        </h2>
        <span style="color: #ccc">&emsp;非指定医生 3分钟快速接诊</span>
      </div>
      <div class="wrap">
        <div class="wrap-left">
          <img src="../../img/ConsultationImg1.png" alt="" />
        </div>
        <div class="wrap-main">
          <h3 style="font-size: 20px; line-height: 0.5rem; margin-top: 0.1rem">
            分钟找到三甲医生
          </h3>
          <p>支持图文/电话/视频问诊</p>
        </div>
        <div class="wrap-rigth">
          <p style="position: absolute; top: 0.2rem">
            <span style="color: red">￥19</span> 起
          </p>
          <van-button
            @click="JumpMedical"
            style="position: absolute; top: 0.5rem"
            type="primary"
            size="small"
            ><b>立即问诊</b></van-button
          >
        </div>
      </div>
      <div>
        <h2
          style="
            display: inline-block;
            height: 0.5rem;
            line-height: 0.5rem;
            margin-left: 0.1rem;
            margin-top: 0.1rem;
          "
        >
          一病多问
        </h2>
        <span style="color: #ccc">&emsp;一次问诊 5为以上专家解答</span>
      </div>
      <div class="wrap">
        <div class="wrap-left">
          <img src="../../img//ConsultationImg2.png" alt="" />
        </div>
        <div class="wrap-main">
          <h3 style="font-size: 20px; line-height: 0.5rem; margin-top: 0.1rem">
            位专家为您解答
          </h3>
          <p>三甲主治医生/主任专家回复</p>
        </div>
        <div class="wrap-rigth">
          <p style="position: absolute; top: 0.2rem">
            <span style="color: red">￥68</span> 起
          </p>
          <van-button
            @click="JumpMedical"
            style="position: absolute; top: 0.5rem"
            type="primary"
            size="small"
            ><b>立即问诊</b></van-button
          >
        </div>
      </div>
      <div>
        <h2
          style="
            display: inline-block;
            height: 0.5rem;
            line-height: 0.5rem;
            margin-left: 0.1rem;
            margin-top: 0.1rem;
          "
        >
          即使倾诉
        </h2>
        <span style="color: #ccc">&emsp;优质心理咨询师快速接诊</span>
      </div>
      <div class="wrap">
        <div class="wrap-left">
          <img src="../../img/ConsultationImg3.png" alt="" />
        </div>
        <div class="wrap-main">
          <h3 style="font-size: 20px; line-height: 0.5rem; margin-top: 0.1rem">
            分钟耐心倾听
          </h3>
          <p>1对1倾听做您的专属陪伴</p>
        </div>
        <div class="wrap-rigth">
          <p style="position: absolute; top: 0.2rem">
            <span style="color: red">￥59</span> 起
          </p>
          <van-button
            @click="JumpMedical"
            style="position: absolute; top: 0.5rem"
            type="primary"
            size="small"
            ><b>立即问诊</b></van-button
          >
        </div>
      </div>
      <div class="ContentFooter">
        <img src="../../img/ConsultationFooter.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import instance from "../axios/index.ts";
import { useCounterStore } from "../pinia/index.ts"; //引入pinia
import { useRouter } from "vue-router";
const router = useRouter();
const value = ref("");

const page = ref(1);
const pageSize = ref(2);
const ContentData = ref([]);
const ContentTitle = ref([]);
const active = ref(0);
const newpifu = ref([]);
let newtitle = ref([]);
let newarr = [];
const store = useCounterStore();
const onChange = (title, active) => {
  newpifu.value = [];
  instance.post("/api/homeall").then((res) => {
    let shuju = res.data.data;
    shuju.map((item) => {
      if (item.department === ContentTitle.value[active]) {
        //所有数据循环判断类型
        newpifu.value.push(item);
      }
    });
    newarr = newpifu.value.splice(page.value * pageSize.value, 2);
    ContentData.value = newarr;
  });
};

const ContentList = () => {
  window.location.href = "/interrogation";
};

instance.post("/api/homeall").then((res) => {
  let newbrr = res.data.data.splice(page.value * pageSize.value, 2);
  ContentData.value = newbrr;
  let shuju = res.data.data;
  shuju.forEach((item) => {
    newtitle.value.push(item.department);
  });
  ContentTitle.value = newtitle.value.filter(
    (element, index) => newtitle.value.indexOf(element) === index //循环去重
  );
});

// 点击数据
const btnvanListDiv = (item) => {
  store.data = item;
  router.push("/consultationDetails");
};

// 搜索
const jumpSearchpages = () => {
  router.push("/home/searchpage");
};

const JumpMedical = () => {
  router.push("/medical");
};
</script>

<style scoped>
.wrap {
  width: 95%;
  height: 1.15rem;
  margin-left: 0.1rem;
  background-color: #fff;
  position: relative;
  display: flex;
  border-radius: 0.15rem;
}

.wrap-left {
  width: 30%;
  height: 100%;
}

.wrap-main {
  width: 50%;
  height: 100%;
}

.wrap-rigth {
  width: 20%;
  height: 100%;
  position: relative;
}

.ContentWrap {
  width: 100%;
  height: 170vh;
  background-color: #f5f7fb;
}

.header {
  width: 100%;
  height: 0.4rem;
}

.main {
  width: 100%;
  height: 50vh;
}

.ContentFooter {
  width: 100%;
  height: 1rem;
}

.ContentFooter img {
  width: 100%;
  height: 100%;
}

.box {
  width: 95%;
  height: 2.85rem;
  background-color: #fff;
  margin-left: 0.1rem;
  position: relative;
  text-align: center;
  margin-top: 0.1rem;
  border-radius: 0.15rem;
}

.box1 {
  width: 100%;
  height: 1rem;
}

.box1 dl {
  width: 100%;
  height: 100%;
  display: flex;
}

.box1 dl img {
  width: 100%;
  height: 100%;
}

.box1 dl dd p {
  text-align: left;
  padding-left: 0.1rem;
  line-height: 0.3rem;
  margin-block-start: 0;
  margin-block-end: 0;
}

.box1 dl dd {
  padding-top: 0.1rem;
}
</style>